/*
 * ADC.c
 *
 *  Created on: Jun 1, 2021
 *      Author: Rupert
 */

#include "FireSensor.h"

#include "stm32f4xx_ll_dma.h"
#include "adc.h"
#include "stm32f4xx_ll_utils.h"

#define V_REF (2.5f)

uint16_t adc_code = 0;

float getADCValue(void)
{
	HAL_ADC_Start(&hadc1);
	HAL_ADC_PollForConversion(&hadc1, 100);
	if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
	{
		adc_code = HAL_ADC_GetValue(&hadc1);
	}
	float voltage = adc_code * V_REF / 4096;
	return voltage;
}
